package com.jspgou.cms.manager.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jspgou.common.hibernate3.Updater;
import com.jspgou.cms.dao.StoreExtDao;
import com.jspgou.cms.entity.Store;
import com.jspgou.cms.entity.StoreExt;
import com.jspgou.cms.manager.StoreExtMng;

@Service
@Transactional
public class StoreExtMngImpl implements StoreExtMng {
	
    public boolean storeNameExist(String storeName){
        return getByStorename(storeName) != null;
    }
    
    public StoreExt getByStorename(String storename){
    	return dao.getByStorename(storename);
    }
	
	public StoreExt save(StoreExt ext, Store store){
		store.setStoreExt(ext);
		ext.setStore(store);
		dao.save(ext);
		store.setStoreExt(ext);
		return ext;
	}

	public StoreExt update(StoreExt ext){
		Updater<StoreExt> updater = new Updater<StoreExt>(ext);
		ext = dao.updateByUpdater(updater);
		ext.blankToNull();
		return ext;
	}

	private StoreExtDao dao;

	@Autowired
	public void setDao(StoreExtDao dao) {
		this.dao = dao;
	}
}